﻿using CyberConnect.Insteon;
using CyberConnect.Insteon.Devices;
using System;

namespace Com
{
    internal class Program
    {
        private static void link_ButtonReportReceived(object sender, ButtonReportEventArgs e)
        { Console.WriteLine("Button Press Event Fired: " + e.Report); }

        private static void link_IncomingMessageReceived(object sender, CyberConnect.Insteon.Messaging.DeviceMessageEventArgs e)
        { Console.WriteLine("IncomingMessageReceived: " + e.IncomingMessage.Message + " [" + e.IncomingMessage.DirectToAddress.ToString() + "]"); }

        private static void Main(string[] args)
        {
            using (PlmLinc link = new PlmLinc("COM1", false))
            {
                link.UpdateConfiguration(new PlmConfiguration(false, true, false, false));

                link.IncomingMessageReceived += link_IncomingMessageReceived; link.ButtonReportReceived += link_ButtonReportReceived;

                ApplianceLinc Lamp = new ApplianceLinc("1E.2D.D2"); Console.WriteLine(Lamp.ToString());
                while (true)
                {
                    ConsoleKeyInfo info = Console.ReadKey();

                    if (info.Key == ConsoleKey.NumPad0 || info.Key == ConsoleKey.D0)
                    { Lamp.SwitchOnOff(link, false); }
                    else if (info.Key == ConsoleKey.NumPad1 || info.Key == ConsoleKey.D1)
                    { Lamp.SwitchOnOff(link, true); }
                    else
                    { Lamp.Ping(link); }
                }
            }
        }
    }
}